<template>
    <Modal v-model="modal" title="编辑项目" @on-cancel="canceledit">
        <Form :model="params" :label-width="80">
            <FormItem label="项目选择">
                <CheckboxGroup v-model="params.project_id">
                    <Checkbox :label="item.value" v-for="item in data" :key="item.value">{{item.label}}</Checkbox>
                </CheckboxGroup>
            </FormItem>
        </Form>
        <div slot='footer'>
            <Button @click="canceledit">取消</Button>
            <Button @click="submitedit" type='primary'>确认</Button>
        </div>
    </Modal>
</template>

<script>
    import { netsettingprojectlist, netsettingbindproject } from '@/api/hqapi';
    export default {
        name: 'Project',
        data () {
            return {
                modal: false,
                params: { id: '', project_id: [] },
                data: []
            };
        },
        methods: {
            initial (row) {
                this.params.id = row.id
                netsettingprojectlist({ id: row.id }).then(res => {
                    this.data = res
                    this.params.project_id = []
                    this.data.forEach(item => {
                        if (item.selected) {
                            this.params.project_id.push(item.value)
                        }
                    });
                    this.modal = true
                })
            },
            canceledit () {
                this.modal = false
            },
            submitedit () {
                let params = {
                    id: this.params.id,
                    project_id: this.params.project_id.join(',')
                }
                netsettingbindproject(params).then(res => {
                    this.$Message.success('绑定项目成功');
                    this.$emit('askData');
                    this.modal = false
                })
            }
        }
    };
</script>

<style lang="scss" scoped>

</style>
